<?php namespace Admin\Controller;
//品牌控制器
class BrandController extends CommonController{
	private $model;
	public function __auto(){
		$this->model = new \Common\Model\Brand;
	}
	
	//品牌列表
	public function index(){
		$data=$this->model->orderby('bsort','DESC')->get();
		if(!$data){
			View::success('请先添加类型',U('add'));
		}
		View::with('data',$data);
		View::make();
	}
	
	//品牌添加
	public function add(){
		if(IS_POST){
			if($this->model->store()){
				View::success("添加成功",U('index'));
			}
			View::error($this->model->getError());
		}
		View::make();
	}
	
	//品牌编辑
	public function edit(){
		if(IS_POST){
			if($this->model->edit()){
				View::success("修改成功",U('index'));
			}
			View::error($this->model->getError());
		}
		$bid=Q('get.bid',0,'intval');
		$data=$this->model->where("bid={$bid}")->find();
		View::with('data',$data);
		View::make();
	}
	
	//品牌删除
	public function del(){
		$bid=Q('get.bid',0,'intval');
		$old=$this->model->where("bid={$bid}")->find();
		$this->model->where("bid={$bid}")->delete();
		$img=$old['blogo'];
		if($img){
			unlink($img);
			$path=str_replace("_thumb","",$img);
			unlink($path);
		}
		View::success("删除成功",U('index'));
	}
}
